<script setup>
import { Search } from '@element-plus/icons-vue'
import { useAppendixStore, useSubjectStore } from '@/stores'
import { ref } from 'vue'
const appendixStore = useAppendixStore()
const subjectStore = useSubjectStore()
const search = ref('')
const loading = ref(false)
const is = ref(true)
is.value = subjectStore.is
appendixStore.getAE()
const degree = [
  {
    value: 1,
    label: '轻度',
    label1: '肯定有关'
  },
  {
    value: 2,
    label: '中度',
    label1: '可能有关'
  },
  {
    value: 3,
    label: '重度',
    label1: '无关'
  }
]
const results = [
  {
    value: 1,
    label: '恢复'
  },
  {
    value: 2,
    label: '恢复但留有后遗症'
  },
  {
    value: 3,
    label: '死亡'
  },
  {
    value: 4,
    label: '不知道'
  },
  {
    value: 5,
    label: '未恢复'
  }
]
const addsearch = async (data) => {
  loading.value = true
  if (data.length === 0) {
    await appendixStore.getAE()
  } else {
    await appendixStore.searchAE(data)
  }
  loading.value = false
}
</script>
<template>
  <div v-if="!is">
    <el-input
      style="width: 200px; margin-right: 10px"
      v-model="search"
      :prefix-icon="Search"
    />
    <el-button @click="addsearch(search)">搜索</el-button>
  </div>
  <el-card class="page-container">
    <div v-if="is" class="header">
      <span>不良事件</span>
      <div>
        <el-input
          style="width: 200px; margin-right: 10px"
          v-model="search"
          :prefix-icon="Search"
        />
        <el-button @click="addsearch(search)">搜索</el-button>
      </div>
    </div>
    <el-table v-loading="loading" :data="appendixStore.AE" stripe>
      <el-table-column prop="idName" label="姓名" />
      <el-table-column prop="name" label="不良事件名称" />
      <el-table-column label="发生日期">
        <template #default="scope">
          <el-date-picker
            v-model="scope.row.startDate"
            type="date"
            placeholder="发生日期"
            disabled
            style="width: 100%"
          />
        </template>
      </el-table-column>
      <el-table-column label="结束日期">
        <template #default="scope">
          <el-date-picker
            v-model="scope.row.finishDate"
            type="date"
            placeholder="结束日期"
            disabled
            style="width: 100%"
          />
        </template>
      </el-table-column>
      <el-table-column label="严重程度">
        <template #default="scope">
          <el-select v-model="scope.row.degree" disabled placeholder="Select">
            <el-option
              v-for="item in degree"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </template>
      </el-table-column>
      <el-table-column prop="measure" label="采取的措施" />
      <el-table-column label="与治疗措施的相关性">
        <template #default="scope">
          <el-select
            v-model="scope.row.relativity"
            disabled
            placeholder="Select"
          >
            <el-option
              v-for="item in degree"
              :key="item.value"
              :label="item.label1"
              :value="item.value"
            />
          </el-select>
        </template>
      </el-table-column>
      <el-table-column label="结果">
        <template #default="scope">
          <el-select v-model="scope.row.result" disabled placeholder="Select">
            <el-option
              v-for="item in results"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </template>
      </el-table-column>
    </el-table>
  </el-card>
</template>
<style lang="scss" scoped>
.page-container {
  min-height: 100%;
  box-sizing: border-box;
  .header {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
}
</style>
